package com.su.lesson02;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class testActionEvent {
    public static void main(String[] args) {
        Frame frame = new Frame();
        frame.setVisible(true);
        frame.setBounds(100, 100, 450, 300);
        //按下按钮，触发一些效果
        Button button = new Button("Click Me");
        frame.add(button,BorderLayout.CENTER);
        //因为addActionListener()需要一个ActionListener ，所以我们需要构造一个ActionListener
       MyActionlister myActionlister = new MyActionlister();
       button.addActionListener(myActionlister);
       windowClose(frame);//关闭
    }
    //关闭窗口的方法
   private static void windowClose(Frame frame){
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
   }
}

//构造
class MyActionlister implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("aaa");
    }
}